home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-17 | 35.7 KB | 975 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: LaunchQuit.Lib
- #
- # Contains: Launching and Quiting tasks
- #
- # Written by: Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
- #
- # Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # <1.0.23> 12/16/93 KTA Fixed but in the new exception handling mechanism.
- # <1.0.22> 12/13/93 KTA Removed calls to ExpectionHandler directly, now call TCSEnd()
- # with a fatal Flag if necessary.
- # <1.0.21> 12/2/93 KTA Added gLaunchTwitchHook1,2,3,4. Also added support for 'PowerPC'
- # and '68k' in gLaunchReqs.
- # <1.0.20> 11/19/93 NAGA modify TCS format
- # <1.0.19> 9/22/93 KTA Problem matching substrings as well are special characters.
- # <1.0.18> 9/22/93 KTA Call the gExceptionHandler task reference instead of calling the
- # task directly.
- # <1.0.17> 9/20/93 KTA LaunchByTypeSelect() Bug Fix - No mem string was returned
- # expected -3 caused an unbalanced TCS stack.
- # <1.0.16> 9/13/93 KTA LaunchTwitch() - intl - regular expressions errors.
- # <1.0.15> 9/10/93 KTA Removed all slang phrases from output.
- # <1.0.14> 9/9/93 KTA Twitcher() - Removed the phrase - 'Sorry Charlie' from the
- # output line.
- # <1.0.13> 9/7/93 KTA BugFix LaunchTwitch() - Problem with ill-formed regular
- # expressions.
- # <1.0.12> 8/25/93 KTA Added support for parity checking the TCS stack.
- # <1.0.11> 8/20/93 KTA LaunchTwitch() - removed duplicate output lines.
- # <1.0.10> 8/20/93 KTA LaunchTwitch() - fixed problem where we were looking in
- # Applemenu before processlist.
- # <1.0.9> 7/30/93 KTA LaunchTwitch(), LaunchByAppleMenu(), LaunchAssist() - updates so
- # when app doesn't have enough memory to launch it will be handled
- # as expected failure.
- # <1.0.8> 7/15/93 KTA Updated references to tasks in Gestalt.Lib whose names had
- # changed.
- # <1.0.7> 7/14/93 KTA Updated for international support
- # <1.0.6> 7/6/93 KTA Merge Michael suggested changes for SPEC
- # <1+> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
- ########################################################################
- # External libraries
- #=======================================================================
- Libraries "TCS.Lib" , "Output.Lib", "String.Lib", "Gestalt.Lib", "StandardFile.Lib", "OnTarget.Lib", "TargetCheck.Lib","UserInterface.Lib";
-
-
- #########################################################################
- # Twitcher(appName)
- #========================================================================
- # Author: DM
- # Description: This Task is intended to select apps from the Process List
- # menu in System 7.0. Use LaunchTwitch to handle launching
- # or twitching applications.
- # This routine selects apps from the Process List.
- # Parameters: appName - app to twitch to.
- # Returns: 0 if twitching to appName fails
- # TheCurrentApp - if twitching was successful
- # Examples: Twitcher("MacWrite 5.0");
- # Assumptions: None
- #========================================================================
- # History:
- # KTA 7/14/93 Changed check for process list from Hide others to Finder
- # KTA 8/24/93 TCS stack parity check
- # KTA 9/9/93 Removed the phrase - 'Sorry Charlie' from the output line
- #########################################################################
- TASK Twitcher(appName := "")
- begin
- returnval:= 0;
- if (Global gIsSys7)
- begin # Was 'Hide Others' changed for intl
- match[menuItem t:"Finder" m:[menu o:?menuOrd] ]!;
- match[application t:?CurrApp];
- tempAppName := "'"+ AppName + "'";
- ApplicationMI := match[menuItem t:/≈{tempAppName}≈/ m:[menu o:menuOrd] ]!;
- if not ( ApplicationMI ) # for special chars in appname
- ApplicationMI := match[menuItem t:appName m:[menu o:menuOrd] ]!;
- if ( ApplicationMI )
- begin
- if not(ApplicationMI.t ~= /Hide≈/!)
- begin
- TCSStart({ 4, global kTCSetLaunch },"Twitch from one application to another via process list");
- select ApplicationMI;
- AppName := ApplicationMI.t;
- LogStr("Twitched to {AppName} by way of the process list",3);
- wait(2);
- TheCurrentApp := MatchApplication(1);
- if(isSubString(appName,TheCurrentApp)) #Check to see if App is frontmost
- returnval:= TheCurrentApp;
- TCSEnd({ 4, global kTCSetLaunch }, returnval,,,"From '{CurrApp}' to '{AppName}'");
- end; # if not(ApplicationMI.t ~= /Hide≈/!)
- end; # if ( ApplicationMI )
- else # not if ( ApplicationMI )
- LogStr("Couldn't select '{appName}' from the process list");
- end; # (Global gIsSys7)
- return(returnval);
- end; # Twitcher()
-
-
- #########################################################################
- # MiniLaunch(appTitle, LaunchApp, SetDir)
- #========================================================================
- # Author: NJV - DMM
- # Description: This routine will launch an application on the target
- # machine(s). The miniLauncher tool should be the running
- # application on the target machine(s). This routine will
- # type the input parameter appTitle to the target machine
- # and then type the return key (which is how an application
- # is launched using miniLauncher.) The application to be
- # launched must reside in a folder beneath the miniLauncher
- # tool in the directory hierarchy. For more information on
- # the miniLauncher tool, see the read-me that accompanies
- # the tool.
- # MiniLauncher can also open or print documents. See the
- # LaunchApp parameter description below for more details.
- #
- # Parameters: appTitle - title of the application or document to be launched.
- # The title does not have to be complete. The MiniLauncher
- # tool will launch the first application it finds
- # starting with the string appTitle. If LaunchApp
- # parameter is not 1, then appTitle will hold the
- # document name to be opened or printed.
- # LaunchApp - 1 to launch application
- # 0 to launch application via a document
- # -1 to print a document (launch app and print)
- # SetDir - 1 to set the default directory to that of the
- # application
- # 0 to bypass setting of default directory (will
- # end up being MiniLauncher's directory).
- #
- # Returns: 1 - Launched OK
- # 0 - Couldn't launch application (usually due to lack of
- # enough memory on the target machine).
- #
- # Examples: MiniLaunch('Word');
- #========================================================================
- # History:
- #
- #########################################################################
- TASK MiniLaunch(appTitle, LaunchApp := 1,SetDir := 1) begin
- returnVal := 0;
- if not(match[window t:"MiniLauncher" o:1]!)
- begin
- MiniLauncher := match[menuitem t:/MiniLauncher≈/ m:[menu t:'']]; # is it in the Apple menu
- if (MiniLauncher) # if so select it
- begin
- select MiniLauncher;
- LogStr("Selected Minilauncher");
- returnVal := 1;
- end;
- else
- LogStr("MiniLauncher is not currently running");
- end;
- else
- returnVal := 1; # Minilauncher is the front window
-
- if(returnVal)
- begin
- Println " -- MiniLauncher --"; # So log reflects what is going down
- # if LaunchApp is 0 check for newest version of MiniLauncher
- foo := match [button t:'Options']!;
- if (LaunchApp <> 1)
- begin
- if (not foo) begin
- if (LaunchApp = -1) # user trying to print document
- LogStr("Wrong version of MiniLauncher for printing documents - use v1.3b or newer.");
- else
- LogStr("Wrong version of MiniLauncher for launching documents - use v1.3b or newer.");
- end;
- else
- SelectButton('Options');
- if (LaunchApp = -1) # user wants to print document
- SelectRadioButton('Print Document');
- else
- SelectRadioButton('Open Document');
-
- SelectButton("OK");
- end;
- else if (foo)
- begin
- SelectButton('Options');
- SelectRadioButton('Launch Application');
- if (SetDir)
- SelectRadioButton("Application∂'s Directory");
- else
- SelectRadioButton("MiniLauncher∂'s Directory");
- SelectButton('OK');
- end;
-
- TypeStr(appTitle);
- SpecialKey(returnKey , "Return Key");
- if(DialogCheck("An error has occurred", 'OK'))
- begin
- returnVal := 0;
- DialogCheck('','OK'); # Any additional dialogs
- end;
- if(returnVal)
- MatchApplication(0);
- end;
- return(returnVal);
- end; # MiniLaunch()
-
- #########################################################################
- # Quit(OverWrite, DocName)
- #=======================================================================
- # Author: KTA
- # Description: Will turn off the Application Verification scheme, Select
- # the Quit menu item, check whether or not to save changes,
- # then reset the App verification scheme to its previous state.
- # Parameters: OverWrite 1 - Save changes.
- # 0 - Don't save changes.
- # DocName - The string that will be used to save the document
- # HowQuit 1 - Select "Quit" from File Menu
- # 2 - Type Cmd-Q to quit
- # CloseScrapbook 1 - close the scrapbook after quitting
- # 0 - don't close the scrapbook after quitting
- # CloseFinderWindows 1 - close finder windows after quitting
- # 0 - don't close finder windows after quitting
- # Returns: -2 - All quitting bypassed (gForceQuit enabled)
- # -1 - Closed all windows of current app (gBackgroundQuit enabled)
- # 0 - Unable to quit current app
- # 1 - successfully quit current app
- #=======================================================================
- # History:
- # KTA 7/7/93 Made the title of the scrapbook a resource, changed references to it.
- # KTA 8/24/93 TCS stack parity check
- # KTA 9/9/93 Removed all slang from output lines.
- #########################################################################
- TASK Quit(OverWrite :=1,DocName:="",HowQuit :=1, CloseScrapbook:=1, CloseFinderWindows:=1)
- begin
- returnval := 0;
- global gAppverify, gstartTime, gBackgroundQuit, gIsSys7, gFillMemory, gFillMemApp, gForceQuit,gScrapTitle;
-
- if not gForceQuit
- begin
- TheCurrentApp := MatchApplication();
-
- if (TheCurrentApp <> 'Finder') # make sure you're not trying to quit the finder
- begin
-
- if ((gBackgroundQuit) and (gIsSys7)) # if Background quit enabled and 7.x
- begin
- logstr('global gBackgroundQuit is enabled so closing all windows instead of actively quitting');
- CloseAllWindows(); # close the open document window
- returnval := -1;
- end;
-
- else if ((gBackgroundQuit) and not (gIsSys7)) # BG quit enabled but not 7.x
- logstr('!@#$% Not System 7.x. Background quit not available. Will actively quit application.');
-
- if (not (gBackgroundQuit) or not (gIsSys7))
- begin
-
- temp := gAppverify;
- gAppVerify := 0;
-
- if (HowQuit = 1)
- begin
- TCSNum := 1;
- TCSStart({ TCSNum, global kTCSetQuit },"Select the 'Quit' menuitem");
- SelectMenuItem('Quit','File'); #Quit MenuItem
- end; # if (HowQuit = 1)
- else if (HowQuit = 2)
- begin
- TCSNum := 2;
- TCSStart({ TCSNum, global kTCSetQuit },"Type command - Q");
- keyEq('q'); #Key Equiv 'q'
- end; # if (HowQuit = 2)
- wait(2);
-
- while(checkYesNo(overwrite))
- begin
- If(overWrite)
- if (match[button t:"Save"]!) or (match[button t:"OK"]!) or (match[button t:"Yes"]!) # If SF dialog comes up #
- SaveAs(DocName,true);
- wait(3);
- end; # while(checkYesNo(overwrite))
-
- # check if TheCurrentApp is no longer in process list
- Twitcher (TheCurrentApp);
- if (MatchApplication(0) = TheCurrentApp)
- logstr("!@#$% Unable to quit '{TheCurrentApp}'!");
- else
- begin
- logstr("Quit '{TheCurrentApp}' successfully.");
- returnval := 1;
- end;
- TCSEnd({ TCSNum, global kTCSetQuit }, returnval);
- end; # if (not (gBackgroundQuit) or not (gIsSys7))
-
- end; # if (TheCurrentApp <> 'Finder')
-
- else # if (TheCurrentApp = 'Finder')
- logstr("It is not possible to quit the Finder!!! ");
-
- # if scrapbook is open, close it
- if (CloseScrapbook)
- begin
- if (typeOf(temp) = 'undefined')
- begin
- temp:= gAppverify;
- gAppverify:=0;
- end;
- Twitcher (gScrapTitle);
- if (MatchApplication(0) = gScrapTitle)
- begin
- closeWindow(,,gScrapTitle);
- wait(2);
- end;
- end; # if CloseScrapbook
-
- # twitch to finder, close all open windows
- Twitcher ("Finder");
- if (MatchApplication(0) = "Finder")
- begin
- if CloseFinderWindows
- KeyEq('w',2);
- end;
- MatchApplication();
- println;
- end; # if not gForceQuit
-
- else # if gForceQuit
- logstr("Global gForceQuit is enabled, so quitting '{global gapptitle}' is bypassed.");
- returnval:= -2;
-
- # if gFillMemory, quit gFillMemApp
- if (gFillMemory)
- begin
- if (typeOf(temp) = 'undefined')
- begin
- temp:= gAppverify;
- gAppverify:=0;
- end;
- Twitcher (gFillMemApp);
- if (MatchApplication(0) = gFillMemApp)
- begin
- Logstr("Trying to quit the gFillMemApp '{gFillMemApp}'");
- TCSNum := 1;
- TCSStart({ TCSNum, global kTCSetQuit },"Selected the 'Quit' menuitem");
- SelectMenuItem("Quit","File"); #Quit MenuItem
- checkYesNo(false);
- wait(2);
- Twitcher (gFillMemApp);
- if (MatchApplication(0) = gFillMemApp)
- begin
- logstr("!@#$% Unable to quit '{gFillMemApp}'");
- TCSEnd({ TCSNum, global kTCSetQuit }, 0);
- end;
- else
- begin
- logstr("Quit '{gFillMemApp}' successfully.");
- TCSEnd({ TCSNum, global kTCSetQuit }, 1);
- end;
- end; # if (MatchApplication(0) = gFillMemApp)
- end; # if (gFillMemory)
-
- if not (typeOf(temp) = 'undefined')
- gAppVerify := temp;
- return(returnval);
-
- end; # Quit()
-
- #########################################################################
- # QuitBackgroundApps()
- #========================================================================
- # Author: ML
- # Description: Checks for Background Quit Dialog, then
- # chooses "quit apps" if BackgroundQuit is ON or
- # "Cancel" if it's OFF.
- # Parameters: None
- # Returns: -2 Couldn't dismiss BG Quit dialog
- # -1 BG Quit dialog present, "Cancel" button selected
- # 0 BG Quit dialog not present
- # 1 BG Quit dialog present, "Quit apps" button selected
- # Assumptions: 7.x
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- #########################################################################
- TASK QuitBackgroundApps()
- begin
- global gBackgroundQuit;
- returnval :=0;
- # dialogcheck doesn't work here, check for background quit buttons
- if (match [button t:/Quit Application≈/]!)
- begin
- match [window t:'' o:1 k:{ [staticText t:?mytext] }]!; # get the static text
- logstr("Found dialog: {mytext}"); # log out the static text
- if (gBackgroundQuit) # if background quit enabled
- begin
- TCSNum := 3;
- TCSStart({ TCSNum, global kTCSetQuit },"BG Quit - Select 'Quit Application(s)'");
- selectbutton (/Quit Application≈/); # select the "Quit Application(s)" button
- returnval := 1;
- wait(15); # long wait in case of multiple background quits
- end; # if (gBackgroundQuit)
- else # not gBackgroundQuit
- begin
- TCSNum := 4;
- TCSStart({ TCSNum, global kTCSetQuit },"BG Quit - Select 'Cancel'");
- selectbutton ('Cancel'); # else don't background quit
- returnval := -1;
- end; # not gBackgroundQuit
- if not match [button t:/Quit Application≈/] # did BG Quit dialog get dismissed?
- TCSEnd({ TCSNum, global kTCSetQuit }, 1); # if so, pass TCS
- else begin # if not, reset returnval, fail TCS
- returnval := -2;
- TCSEnd({ TCSNum, global kTCSetQuit }, 0);
- end;
- end; # if (match [button t:/Quit Application≈/]!)
- return(returnval);
- end;
-
- #########################################################################
- # TwitchQuit()
- #========================================================================
- # Author: ML
- # Description: Selects the fifth item (first app or da) in the process list, or sixth
- # if the fifth is "Finder", and quits it.
- # Parameters: None
- # Returns: 0 - Could not quit an app or da
- # 1 - quit app or da ok
- # Assumptions: 7.0x - There is a process list
- #========================================================================
- # History:
- #
- ########################################################################
- TASK TwitchQuit()
- begin
-
- global gIsSys7, gForceQuit, gBackgroundQuit, gAppverify, gFillMemory;
- returnval:=0;
-
- if ((gIsSys7) and (gForceQuit))
- begin
- Twitcher('Finder'); # make sure we're starting from the finder
- logstr('Attempting to twitch to and quit the first open app or DA');
- match[menuItem t:"Hide Others" m:[menu o:?menuOrd] ]!; # get ord of process list
- match[menuItem o:5 t:?AppToQuit m:[menu o:menuOrd] ]!; # get title of app to quit
- if (AppToQuit = 'Finder') # if fifth menuitem is finder
- match[menuItem o:6 t:?AppToQuit m:[menu o:menuOrd] ]!; # get title of sixth
-
- if (AppToQuit <> 'Finder') # if we've identified an app to quit
- begin
- temp := gAppverify;
- gAppverify := 0;
- if (AppToQuit = Twitcher(AppToQuit)) # twitch to it
- begin
- temp1 := gBackgroundQuit; # set globals
- gBackgroundQuit := 0; # for active quit
- temp2 := gForceQuit;
- gForceQuit := 0;
- temp3 := gFillMemory;
- gFillMemory := 0;
- returnval := Quit(,,,0,0); # call Quit Task
- gBackgroundQuit := temp1;
- gForceQuit := temp2;
- gFillMemory := temp3;
- end; # (AppToQuit = (Twitcher(AppToQuit))
-
- else # couldn't twitch to app
- logstr("!@#$% Could not twitch to {AppToQuit}.");
-
- gAppverify := temp;
- end; # if (AppToQuit <> 'Finder')
- else # AppToQuit still equals finder - nothing to quit
- logstr("Unable to identify any applications or DA's to quit.");
-
- end; # if ((gIsSys7) and (gForceQuit))
- else
- returnval:=-1;
-
- return(returnval);
- end; # TwitchQuit()
-
- #########################################################################
- # LaunchAssist()
- #========================================================================
- # Author: ML
- # Description: Assist launch process by background quitting, checking
- # for "not enough memory" dialogs, and twitch and quitting.
- # Parameters: None
- # Returns: -3 - unsuccessful- not enough memory
- # -2 - unsuccessful - background quit cancelled
- # -1 - unsuccessful - twitchquit failed
- # 0 - unsuccessful - alias not found
- # 1 - successful launch
- # 2 - successful twitchquit
- # Assumptions: 7.0x - There is a process list
- #========================================================================
- # History:
- # ML 7/1/93 if BG quit cancelled, if gForceQuit is true, then do TwitchQuit.
- #
- ########################################################################
- TASK LaunchAssist()
- begin
- returnval:=0;
- if not DialogCheck(/could not be found≈(≈∂n≈)*/,'OK')
- begin
- myBGQuit := QuitBackgroundApps(); # check for BG quit dialog
- if (myBGQuit = -1) # if BG Quit Dialog is cancelled
- begin
- returnval:=-2; # set returnval to indicate this
- if not global gForceQuit # if gForceQuit is false
- return(returnval); # return returnval, end task
- end;
- # if BG quit cancelled and gForceQuit true, or not enough memory dialog
- NoMemError := DialogCheck(/memory≈(≈∂n≈)*/,'OK');
- if (returnval= -2 or NoMemError)
- begin
- if (TwitchQuit() = 1) # try to twitch and quit
- returnval:= 2; # successful twitchquit
- else if (TwitchQuit() = -1)
- returnval:= NoMemError ; # No memory
- else
- returnval:= -1; # twitchquit failed
- end; #
- else # no cancelled BG quits, no memory dialogs
- returnval:=1; # successful launch
- end; # if not DialogCheck(/could not be found≈(≈∂n≈)*/,'OK')
- return(returnval);
- end;
-
- #########################################################################
- # LaunchByAppleMenu()
- #========================================================================
- # Author: ML
- # Description: Launch via the Apple Menu
- # Parameters: ItemName - name of app or DA to launch
- # Returns: -3 - unsuccessful- not enough memory
- # -2 - unsuccessful - background quit cancelled
- # -1 - unsuccessful - twitchquit failed
- # 0 - unsuccessful - alias not found
- # 1 - successful launch
- # Assumptions: 7.0x - There is a process list
- # ItemName is in apple menu
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- #########################################################################
- TASK LaunchByAppleMenu(ItemName)
- begin
- TCSStart({ 1, global kTCSetLaunch },"Selected an item in Apple Menu");
- returnval:= 2; # initialize value for loop
- While returnval = 2 # if first pass or twitchquit successful
- begin
- Selectmenuitem("{ItemName}", ""); # Select Apple MenuItem
- wait(2);
- returnval:= LaunchAssist() ; # assist launch
- end; # While returnval = 2
-
- if (returnval = 1)
- TCSEnd({ 1, global kTCSetLaunch },1,,,"{ItemName}");
- else if (TypeOf(returnval) = 'string') # out of memory
- begin
- TCSEnd({ 1, global kTCSetLaunch }, -1, returnval);
- returnVal := -3;
- end;
- else if (returnval = -2)
- TCSEnd({ 1, global kTCSetLaunch }, 0, 'Background quit cancelled');
- else if (returnval = -1)
- TCSEnd({ 1, global kTCSetLaunch }, 0, 'TwitchQuit failed');
- else if (returnval = 0)
- TCSEnd({ 1, global kTCSetLaunch },-1, 'alias not found');
- return (returnval);
- end;
-
- #########################################################################
- # LaunchByTypeSelect()
- #========================================================================
- # Author: ML
- # Description: Launch via type select
- # Parameters: AppName - name of app or DA to launch
- # AliasDir - name of alias directory
- # Returns: -3 - unsuccessful- not enough memory
- # -2 - unsuccessful - background quit cancelled
- # -1 - unsuccessful - twitchquit failed
- # 0 - unsuccessful - other
- # 1 - successful launch
- # Assumptions: 7.0x - There is a process list
- #========================================================================
- # History:
- # KTA 7/7/93 Changed SelectMenuItem('Open','File'); to KeyEq('o'); for intl
- # KTA 8/24/93 TCS stack parity check
- # KTA 9/20/93 Bug Fix - No mem string was returned expected -3 caused
- # an unbalanced TCS stack
- #########################################################################
- TASK LaunchByTypeSelect(AppName, AliasDir := "")
- begin
- returnval:= 0;
- if AliasDir # if alias directory parameter passed
- begin
- if (match [menuItem t:AliasDir m:[menu t:""]]) # if AliasDir in the apple menu
- begin
- if (LaunchByAppleMenu(AliasDir) = 1) # if successful opening AliasDir
- begin
- if (FindWindow(/≈{AliasDir}≈/)) # Is the right folder open
- begin
- TCSStart({ 2, global kTCSetLaunch },"Launch via Type Select");
- typeStr("{AppName}"); # Type the appName
- returnval:= 2; # initialize value for loop
- While returnval = 2 # if first pass or twitchquit successful
- begin
- KeyEq('o'); # Open Intl
- wait(2);
- returnval:= LaunchAssist() ; # assist launch
- if(TypeOf(returnval = 'string'))
- begin
- if(isSubString(/memory≈(≈∂n≈)*/, returnVal))
- returnVal := -3;
- end;
- end; # While returnval = 2
-
- tempAppName := "'"+ AppName + "'"; # This is handle a problem that special characters can cause
- if (match[application t:/≈{tempAppName}≈/])
- TCSReturnVal := 1;
- else
- TCSReturnVal := 0;
-
- if (returnval = 1)
- TCSEnd({ 2, global kTCSetLaunch },TCSReturnVal,,,"{AppName}");
- else if (returnval = -3)
- TCSEnd({ 2, global kTCSetLaunch },-1, 'not enough memory');
- else if (returnval = -2)
- TCSEnd({ 2, global kTCSetLaunch },0, 'Background quit cancelled');
- else if (returnval = -1)
- TCSEnd({ 2, global kTCSetLaunch },0, 'TwitchQuit failed');
- else if (returnval = 0)
- TCSEnd({ 2, global kTCSetLaunch },-1, 'alias not found');
- end; # if (FindWindow(/≈{AliasDir}≈/))
- else
- logstr("The alias directory '{AliasDir}' wasn't opened");
- end; # if successful opening AliasDir
- else
- logstr("Unable to launch the '{AliasDir}' Apple menu item");
- end; # if AliasDir in the apple menu
- else
- logstr("The alias directory '{AliasDir}' is not an apple menu item");
- end; # if alias directory parameter passed
- else
- logstr("No alias directory defined");
- return (returnval);
- end;
-
- #########################################################################
- # LaunchFillMemApp()
- #========================================================================
- # Author: ML
- # Description: Launch global gfillMemApp
- # Parameters: None
- # Returns: none
- # Assumptions: 7.0x - There is a process list
- # Alias or original of gFillMemApp is in apple menu
- # or in alias directory. Memory allocation of gFillMemApp
- # has been set high enough to fill up remaining memory.
- #========================================================================
- # History:
- # ML 6/30/93 Set SuiteBailOut parameter in call to LaunchTwitch() to 0
- ########################################################################
- TASK LaunchFillMemApp()
- begin
- # set globals so no recursive quitting/launching
- tempgBackgroundQuit:= global gBackgroundQuit;
- gBackgroundQuit:= 0;
- tempgForceQuit:= global gForceQuit;
- gForceQuit:= 0;
- tempgFillMemory:= global gFillMemory;
- gFillMemory:= 0;
-
- # launch gFillMemApp
- LaunchTwitch(global gFillMemApp, global gAliasDirectory,,0);
-
- # reset globals
- gBackgroundQuit:= tempgBackgroundQuit;
- gForceQuit:= tempgForceQuit;
- gFillMemory:= tempgFillMemory;
- end;
-
-
- #########################################################################
- # LaunchTwitch(AppName, AliasDir, LaunchApp, SuiteBailOut)
- #========================================================================
- # Author: KTA
- # Description: This routine determines whether the Operating system is
- # 6.0x or 7.0x and launches the application accordingly.
- # 6.0x - Will check the Apple menu to see if the App is
- # currently running and select it if it is. If it is not running
- # it will select Mini from the Apple menu and call MiniLaunch(AppName);
- # 7.0x - Will check the ProcessList to see if the App is
- # currently running and select it if it is. if it is not it will
- # Select the Apple from the Apple Menu, or the <AliasDir> and then type
- # the <AppName> and select the Open menuItem.
- # Parameters: AppName - Application to be launched/Twitched
- # AliasDir - Folder in the Apple menu that contains <AppName>.
- # LaunchApp - 0 Select from Process list - Do not launch the App.
- # 1 Select from Process list or launch the App if
- # necessary.
- # SuiteBailOut - 1 Call ExceptionHandler(-70) to bail out of suite if
- # LaunchTwitch fails
- # 0 Don't call ExceptionHandler(-70) to bail out of suite if
- # LaunchTwitch fails
- # Returns: 0 - App did not launch
- # AppName - Name of app that launched
- # Examples: LaunchTwitch('MacWrite', "#CoreAliases");
- # LaunchTwitch('MacWrite Doc',"#CoreAliases",0);
- # Assumptions: 7.0x - That the Application (or Alias) is resident in the
- # Apple Menu or the <AliasDir> which contains <AppName> is.
- #========================================================================
- # History:
- # ML 7/1/93 Set default AliasDir to global gAliasDirectory
- # Check for modal dialog before launching gFillMemApp
- # Reset globals, if necessary, after all launching done
- # KTA 8/20/93 Bug Fix : we were looking in Applemenu before seeing
- # if app was running.
- # KTA 8/24/93 TCS stack parity check
- # KTA 9/7/93 problem with ill-formed regular expressions
- # KTA 9/22/93 Problem matching substrings as well are special characters
- # KTA 12/01/93 gPatchLaunchTwich is now a global hook, made task more readable
- # KTA 12/01/93 Added gLaunchTwitchHook1, gLaunchTwitchHook2, gLaunchTwitchHook3,
- # and gLaunchTwitchHook4
- # KTA 12/13/93 Preflight now fails TCS instead of calling ExceptionHandler directly
- #########################################################################
- TASK LaunchTwitch(AppName, AliasDir:= global gAliasDirectory, LaunchApp := 1, SuiteBailOut:=1)
- begin
- FailStr := ''; # Init misc variables
- returnVal := 0;
-
- # Turn off app verification scheme temporarily
- tempAppVerify := global gAppVerify;
- gAppVerify := 0;
-
- TCSStart({ 3, global kTCSetLaunch },"Launch or twitch to an application");
-
- if (global gLaunchTwitchHook1) # Hook prior to preflight
- Call (gLaunchTwitchHook1);
-
- if (global gPreFlight) # if we've set up our globals for preflight of app
- begin
- if (global gLaunchReqs) # If we've defined any launch req's
- begin
- preFlightVal := PreFlight(gLaunchReqs);
- if not (preFlightVal[1]) # If any of our launch req's are not satisfied
- begin # Fatal error
- PreflightString := preFlightVal[2];
- TCSEnd({ 3, global kTCSetLaunch },-1,"Failed the launch requirements for '{AppName}' - {PreflightString}",,,,-1);
- end;
- else
- global gLaunchReqs := {}; # We passed the preflight now reset the launchreqs so we don't call preflight everytime thereafter.
- end;
- end;
- tempAppName := "'"+ AppName + "'"; # This is handle a problem that special characters can cause within
- # regular expressions
- if not(match[application t:/≈{tempAppName}≈/]) # if desired app is not the current app
- begin
- if (global gLaunchTwitchHook2) # Hook prior to launching
- Call (gLaunchTwitchHook2);
-
- tempTypeSpeed := typespeed(50); # assign current typespeed to temp, then set to 50
- global gPrevAppTitle := global gAppTitle; # Set previous app to the current app
- if (global gPatchLaunchTwitch) # if we want to patch Launchtwitch
- call(gPatchLaunchTwitch, AppName, AliasDir,LaunchApp);
- else # Were going to attempt to launch or twitch to the app
- begin
- if(global gIsSys7)
- begin
- launchedByProcessList :=Twitcher(AppName);
- if(launchedByProcessList)
- returnVal := launchedByProcessList;
- else
- begin
- # Is it in the Apple Menu ?
- AppleMenuMatch := match[menuItem t:/≈{tempAppName}≈/ o:?menuord m:[menu t:""]]!;
- if (AppleMenuMatch)
- returnval:= LaunchByAppleMenu(AppleMenuMatch.t);
-
- if (global gLaunchTwitchHook3) # Hook prior to launching by type selecting
- Call (gLaunchTwitchHook3);
-
- if ( returnval = 0) and (LaunchApp)# if not in apple menu or alias not found
- returnval:= LaunchByTypeSelect(AppName, AliasDir);
- end;
- end;
- else # Must be a 6.0.x System so we will launch with minilauncher
- returnVal := Minilaunch(AppName); # System 6 branch
- end;
-
- if TypeOf(returnval) = 'string' # Twitcher returns a string
- returnval:= 1;
-
- if returnval > 0 # we're OK so far - keep checking
- begin
- ## Check to insure application actually launched
- # 6.0 support Da's are not applications
- if ( match[application t:/≈{tempAppName}≈/]) or (Match[window o:1 t:"{AppName}"])
- returnVal := MatchApplication(0);
- else # Desired application is not running
- returnVal := 0;
- end;
- else
- begin
- if (returnVal = -3) # LaunchByAppleMenu returned not enough memory
- FailStr := "Not enough memory to launch";
- else
- returnVal := 0; # BG quit cancelled, twitchquit failed, or out of memory
- end;
- end;
- else # Desired App must be running
- returnVal := MatchApplication();
-
- if (returnval) # if we're up and running
- begin
- if (global gFillMemory) # if global to fill up memory set on
- begin
- if not (DialogCheck(,,,[window o:1 s:dialog]!)) # make sure we're not modal - bail out if opening dialog present
- begin
- LaunchFillMemApp(); # launch the gFillMemApp
- Twitcher(returnval); # twitch back
- end; # if not DialogCheck(,,,[window o:1 s:dialog]!)
- else # there was an opening dialog present
- logstr("Opening dialog present. Can't launch gFillMemApp");
- end;
- end;
- else # we failed our launch of gFillMemApp
- logstr("'{AppName}' couldn't be launched successfully");
-
- # Reset the global values to their original values if necessary
- gAppVerify := tempAppVerify; # assign back the original value
- if not (typeof(tempTypeSpeed) = 'undefined') # if typespeed has been reassigned
- typespeed(tempTypeSpeed); # assign back the original value
-
- ### Set TCS ReturnValues
- if (returnval) # We were successful
- begin
- if(returnval = -3) # Not enough memory expected fail
- begin
- if (SuiteBailOut)
- BailFlag := -1;
- else
- BailFlag := '';
- TCSEnd({ 3, global kTCSetLaunch }, -1, FailStr,,,,BailFlag); # Launch failed/ Bail the suite
- returnVal := 0; # no memory means launch actually failed
- end;
- else
- TCSEnd({ 3, global kTCSetLaunch },1,,,"Launch or twitch to '{AppName}'");
- end;
- else # Otherwise
- TCSEnd({ 3, global kTCSetLaunch },0); # we were unsuccessfull - return a 0
-
- if (global gLaunchTwitchHook4) # Hook prior returning
- Call (gLaunchTwitchHook4);
-
- return(returnVal);
- end; # LaunchTwitch();
-
- #########################################################################
- # PreFlight(List) - Called by LaunchTwitch, Set global
- # gLaunchReqs to parameter list.
- #========================================================================
- # Author: GS
- #
- # Description: This routine will test whether or not your script will run on the
- # targets hardware and software configuration. PreFlight will test
- # the machine for each selectors specified and return a fail if any
- # of the selectors fail.
- #
- # Parameters: 'fpu' Returns a fail on machines that do not have an fpu.
- # 'color' Returns a fail on machines that are not set to color.
- # '8bd' Returns a fail on machines that are not set to at least 8bit depth.
- # 'no68K' Returns a fail on 68000 machines.
- # 'noCache' Returns a fail on '040's that have caching turned on.
- # 'no32' Returns a fail on cpu's with 32 bit addressing turned on
- # '68k' Returns a fail on cpu's that are not 68k based
- # 'PowerPC' Returns a fail on cpu's that are not PowerPC based
- #
- # Returns: fail: {0, 'Error Message'}
- # pass: {1, ''}
- #
- # Examples: gLaunchReqs = {'fpu', 'color', '8bd', 'no68K', 'noCache'};
- #
- #========================================================================
- # History:
- # KTA 12/1/93 Added support for 'PowerPC' and '68k' in gLaunchReqs
- # KTA 12/1/93 fixed a bug in 'no32'
- # KTA 12/13/93 Preflight now returns a List with an error indicator and error message
- #########################################################################
- TASK PreFlight(myList)
- begin
- returnVal := 0;
- ErrorString := '';
-
- for each item in myList
- begin
-
- #Test for fpu, drop out if not available
- if (item = 'fpu')
- begin
- if(GestaltFPUType() = "NoFPU")
- ErrorString := "This app requires an fpu and there is no fpu";
- end;
-
- #Test for PowerPC, drop out if not available
- if (item = 'PowerPC')
- begin
- if not(IsPowerPC())
- ErrorString := "PowerPC machine required and this target is 68k based";
- end;
-
- #Test for 68k, drop out if not available
- if (item = '68k')
- begin
- if (IsPowerPC())
- ErrorString := "68k based machine required and this target is PowerPC based";
- end;
-
-
- #Test for color
- if (item = 'color')
- begin
- match [screen m:true c:?isColor]!;
- if not (isColor)
- ErrorString := "Color required and the menu monitor is not set to color";
- end;
-
-
- #Test for at least 8 bit color
- if (item = '8bd')
- begin
- match [screen m:true p:?PixelDepth]!;
- if not (PixelDepth >= 8)
- ErrorString := "At least 8 bit video required";
- end;
-
-
- #Test for 68000
- if (item = 'no68K')
- begin
- if(GestaltProcessorType() = "68000")
- ErrorString := "CPU with a processor greater than 68000 required";
- end;
-
-
- #Test for Cache
- if (item = 'noCache')
- begin
- if(OnTargetInit())
- begin
- if(OnTarget("CacheTest")[2] = 1)
- ErrorString := "Requires that 040 Caching turned - OFF";
- end;
- end;
-
- if (item = 'no32')
- begin
- if(Check32Bit()[1] = 1)
- ErrorString := "Requires that 32 bit addressing turned - OFF";
- end;
- end;
-
- if not (errorString) # IF there was no errorString Preflight passed
- returnVal := 1;
-
- return({returnVal,ErrorString}); # nothing failed
- end;
-
-